using System;
using UnityEngine;

namespace EventBehaviorTree
{
    [Serializable]
    public class InstantTask : EventNode
    {
        private Action[] _actions;
        public InstantTask(params Action[] actions) { SetAction(actions); }

        public override void SetCoroutineStarter(MonoBehaviour coroutineStarter) { }

        public void SetAction(params Action[] actions) { _actions = actions == null ? new Action[] { } : actions; }

        public override void NodeEvent(NodeMsg nodeMessage)
        {
            if (nodeMessage == NodeMsg.Start)
            {
                foreach (Action action in _actions) action();
                SuperiorNodeEvent(NodeMsg.Succeed);
            }
        }
    }
}
